/*
 * Tweet keyword and target word match
 */

package crypto;

import java.lang.String;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 *
 * @author Cecilia Bartley
 */

public class Word_Match {


    public Set<String> ScrambleRecursion(String W2S) {
        return ScrambleRecursion(W2S, "", new LinkedHashSet());
    }

//W2S is Word to Scramble, stub is the first word in the string, 
    private Set<String> ScrambleRecursion(String W2S, String stub, Set<String> output){
        if (W2S.length() ==1)
        {
            String out = stub + W2S; //first word + all other remaining characters within the string
            output.add(out);
            return output;
        }
        for (int i=0; i<W2S.length(); i++)
        {
            String newStub = stub + W2S.charAt(i);
            String newW2S = W2S.substring(0,i) + W2S.substring(i+1);
            ScrambleRecursion(newW2S, newStub, output);
        }
        return output;
    }
    //Checks to see if the string contains the word, and returns true of false.
public boolean cc(String text, String word){
        return text.contains(word);
        
}
// Just an i++ example that Isaac was showing me, not related to the class
    public void cc3(){
    int i = 0;
    int j = 0;
    int k = j + 1;
    i++;
    System.out.println(i);
    System.out.println(j);
    System.out.println(k);

}
// Creates an array list and matches the words within the string against the search word based on the length of the search word
//  holds the value of the value of where the character match is in an array list
    public ArrayList<Integer> cc2(String text, String search){
     ArrayList a = new ArrayList();
      for (int i = 0; i<text.length(); i++)
            {
         //System.out.println(i);
         String temptext = text.substring(i,i+search.length());//i+search len
          boolean swit = temptext.equalsIgnoreCase(search); //swit means search word in text
              if (swit)
                  a.add(i);
              if (i + search.length()>= text.length())//check the condition to make sure it is correct.  Does if run until the length of the text.
                 break;
      }
        return a;
    }

       

    public static void main(String args[]){
        Set finalOutput = new HashSet();
        String stub = "";
        String W2S = "boy";

        Word_Match test = new Word_Match ();
        Set<String> ScrambleRecursion = test.ScrambleRecursion(W2S, stub, finalOutput);
        boolean cc = test.cc("Why are you getting frustrated Isaac?", "nail"); //testing to see if the method works
        //test.cc3();
        ArrayList<Integer> cc2 = test.cc2("Cecilia is a UALR students ", "s ");
        System.out.println(cc2);
    }

}


